package com.wyman.context.annotation;

import cn.hutool.core.util.ClassUtil;
import com.wyman.beans.factory.config.BeanDefinition;
import com.wyman.stereotype.Component;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @Author 李伟民
 * @Description
 * @DateTime 2024/12/29 22:50
 */
//借用hutool的能力 后获取指定包下 所有含有@Component注解的类 封装为Befinition返回
public class ClassPathScanningCandidateComponentProvider {

    public Set<BeanDefinition> findCandidateComponents(String basePackage){
        Set<BeanDefinition> candidates = new LinkedHashSet<>();
        Set<Class<?>> classes = ClassUtil.scanPackageByAnnotation(basePackage, Component.class);
        for(Class<?> clazz:classes){
            candidates.add(new BeanDefinition(clazz));
        }
        return candidates;
    }

}
